package com.gitee.chenyaohua.oa.util.zip;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import lombok.extern.slf4j.Slf4j;


@Slf4j
public class JarUtils {

	
	public static List<JarEntry> getFiles(String jarPath,String packPath){
		List<JarEntry> list = new ArrayList<>();
		try {
			String replaceAll = packPath.replaceAll("\\.", "/");
			JarFile jarfile = new JarFile(new File(jarPath));
			Enumeration<JarEntry> entries = jarfile.entries();
			
			while(entries.hasMoreElements()) {
				JarEntry nextElement = entries.nextElement();
				if(nextElement.isDirectory()) {
					continue;
				}
				String name = nextElement.getName();
				if(name.startsWith(replaceAll)) {
					list.add(nextElement);
				}
			}
		} catch (IOException e) {
			log.error("jar 压缩包获取class文件失败：",e);
		}
		
		return list;
	}
	
}
